package com.speciality.demo.demos.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.speciality.demo.demos.entity.WeatherDaily;
import com.speciality.demo.demos.entity.WeatherHourly;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface WeatherDailyMapper extends BaseMapper<WeatherDaily> {
    List<WeatherDaily> selectDailyByTimeRange(
            @Param("startDate") LocalDate startDate,
            @Param("endDate") LocalDate endDate
    );
    /**
     * 获取指定日期范围内的天气数据
     */
    @Select("SELECT * FROM weather_daily WHERE date BETWEEN #{startDate} AND #{endDate} ORDER BY date")
    List<WeatherDaily> selectByDateRange(@Param("startDate") LocalDate startDate,
                                         @Param("endDate") LocalDate endDate);

    /**
     * 获取历史同期数据（用于预测参考）
     */
    @Select("SELECT * FROM weather_daily WHERE MONTH(date) = MONTH(#{date}) AND DAY(date) = DAY(#{date}) AND YEAR(date) < YEAR(#{date}) ORDER BY date DESC LIMIT 5")
    List<WeatherDaily> selectHistoricalSamePeriod(@Param("date") LocalDate date);

    /**
     * 获取温度统计信息
     */
    @Select("SELECT AVG(temperature2m_max) as avg_max_temp, AVG(temperature2m_min) as avg_min_temp FROM weather_daily WHERE date BETWEEN #{startDate} AND #{endDate}")
    Map<String, Object> selectTemperatureStats(@Param("startDate") LocalDate startDate,
                                               @Param("endDate") LocalDate endDate);



}
